package com.yl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yl.entity.AppCategoryEntity;
import com.yl.service.AppCategoryService;
import com.yl.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class AppCategoryController {

    @Resource
    private AppCategoryService appCategoryService;


    /**
     * 查询所有分类
     */
    @PostMapping("/getCategoryList")
    public R getCategoryList(@RequestBody AppCategoryEntity appCategoryEntity) {
        IPage<AppCategoryEntity> categoryList = appCategoryService.getCategoryList(appCategoryEntity);
        return R.ok("查询分类数据成功!").put("data", categoryList);
    }

    /**
     * 添加分类
     */
    @PostMapping("/add")
    public R addCategory(@RequestBody AppCategoryEntity appCategoryEntity) {
        R r = appCategoryService.addCategory(appCategoryEntity);
        return r;
    }

    /**
     * 删除分类
     */
    @PostMapping("/remove/{id}")
    public R removeCategory(@PathVariable("id") Long id) {
        R r = appCategoryService.deleteCategory(id);
        return r;
    }

    /**
     * 修改分类
     *
     * @param appCategoryEntity
     * @return
     */
    @PostMapping("/edit/{id}")
    public R editCategory(@RequestBody AppCategoryEntity appCategoryEntity) {
        R r = appCategoryService.updateCategory(appCategoryEntity);
        return r;
    }

    /**
     * 根据ID查询分类数据
     *
     * @param id
     * @return
     */
    @PostMapping("/info/{id}")
    public R infoCategory(@PathVariable("id") Long id) {
        AppCategoryEntity appCategoryEntity = appCategoryService.getById(id);
        return R.ok("查询成功!").put("data", appCategoryEntity);
    }
}
